<?
global $frm, $smarty, $settings, $premiumGroupId;


$groupId = $frm ['type'];
$newlisting = $frm ['new'];
$orderby = "";
$activeGroup=null;
$active = "active";
if($newlisting == "1" ){
	if($groupId == GlobalConst::$PREMIUM_GROUP_ID){
		$activeGroup = $active;
	}
	$orderby = "added desc";
}else{
	$orderby = "started";
}
if($groupId != $premiumGroupId && $groupId != $scamGroupId && $groupId != $closeGroupId){
	$groupId = $premiumGroupId;
}

$q = 'select 
                  *,
                  date_format(date_added, \'%b %D, %Y\') as added,
                  date_format(date_started, \'%b %D, %Y\') as started,
                  date_format(date_closed, \'%b %D, %Y\') as closed,
                  unix_timestamp(date_added) as adate,
                  unix_timestamp(date_updated) as udate,
                  unix_timestamp(date_closed) as cdate,
                  (to_days(now()) - to_days(date_added)) as monitored,
                  (date_added + interval ' . $settings ['new_for_days'] . ' day > current_date) as new
           from
                  hl_listings 
           where 
                  group_id =' . $groupId . ' and (expiration = 0 || date_added + interval expiration day >= current_date) 
                  and status = ' . GlobalConst::$PROGRAM_APPROVAL . ' order by '.$orderby;

$sth = mysql_query ( $q );
$listings = array ();
while ( $listing = mysql_fetch_array ( $sth ) ) {
	$listing = get_listing_details($listing);
	array_push ( $listings, $listing );
}

$smarty->assign ( 'listings', $listings );
$smarty->assign ( 'groupId', $groupId );
$smarty->assign ( 'activeGroup', $activeGroup );
$smarty->assign ( 'active', $active );
$smarty->display ( 'home.tpl' );

?>
